package com.li.aop.logs.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Aspect
public class SecurityAspect {

    @Pointcut("execution(* com.li.aop.logs.service..save*(..))")
    public void savePointCut(){}

    @Pointcut("execution(* com.li.aop.logs.service..delete*(..))")
    public void deletePointCut(){}

    @Pointcut("execution(* com.li.aop.logs.service..modity*(..))")
    public void modifyPointCut(){}

    @Pointcut("execution(* com.li.aop.logs.service..select*(..))")
    public void selectPointCut(){}

    @Before("savePointCut() || deletePointCut() || modifyPointCut() || selectPointCut()")
    public void beforeAdvice(JoinPoint joinPoint) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        String nowTime = sdf.format(new Date());
        //此时没有登录用户，模拟登录用户信息
        System.out.println(nowTime + " 张三：" + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    }
}
